# coding=utf-8
# 本题为考试多行输入输出规范示例，无需提交，不计分。
import sys
from typing import List


def getRes(samples: List[List]):
    # find the longest road
    # 思路：对于第i个站点，计算起点到该站点耗费的最少金钱.cost(i)
    # cost(i) = min(cost(i-1)+possible_cost,cost(i-2)+possible_cost,....)
    n, k = samples[0]
    distance = samples[1]
    cost = samples[2]
    for i in range(len(distance) - 1):
        if distance[i + 1] - distance[i] > k:
            return -1
    price = [1000000000 for _ in range(n)]
    left_distance = [0 for _ in range(n)]
    left_distance[0] = k - distance[0]
    price[0] = 0
    for i in range(1, n):
        for j in range(0, i):
            j = i - 1 - j
            if k < distance[i] - distance[j]:
                break
            if left_distance[j] >= (distance[i] - distance[j]):
                # if price[j] <
                price[i] = min(price[j], price[i])
                left_distance[i] = left_distance[j] - (distance[i] - distance[j])
            else:
                price[i] = min(price[j] + cost[j], price[i])
                left_distance[i] = k - (distance[i] - distance[i - 1])
    return price[n - 1]


if __name__ == "__main__":
    # 读取第一行的n，n个测试数据
    n = int(sys.stdin.readline().strip())
    values = []
    for i in range(n):
        value = []
        for j in range(3):
            # 读取每一行
            line = sys.stdin.readline().strip()
            # 把每一行的数字分隔后转化成int列表
            temp_value = list(map(int, line.split()))
            value.append(temp_value)
        values.append(value)
    ans = []
    for value in values:
        ans.append(getRes(value))
    for i in range(len(ans)):
        print(ans[i])
